package cn.glutnn.auth.application.entity;

import lombok.Data;

/**
 * Author:   msh
 * Date:     2024/11/21 下午2:21
 * Description:
 */

@Data
public class Result<T> {
    private boolean success;
    private Integer code;
    private String message;
    private T data;

    public static Result ok() {
        Result result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        return result;
    }

    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        result.setData(data);
        return result;
    }

    public static Result fail() {
        Result result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAILED.getCode());
        result.setMessage(ResultCodeEnum.FAILED.getDesc());
        return result;
    }

    public static <T> Result<T> fail(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAILED.getCode());
        result.setMessage(ResultCodeEnum.FAILED.getDesc());
        result.setData(data);
        return result;
    }

    public static Result fail(String msg) {
        Result result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAILED.getCode());
        result.setMessage(msg);
        return result;
    }

    public boolean getSuccess() {
        return success;
    }
}
